//
//  UIImage+Category.swift
//  Super_WeiBo
//
//  Created by SuperMac on 16/6/13.
//  Copyright © 2016年 lc. All rights reserved.
//

import UIKit

extension UIImage
{
    func imageWithSecale(width: CGFloat) -> UIImage
    {
        // 根绝原宽高比，计算新的图片宽度
        let height = width * size.height / size.width
        //  按照新的宽高绘制一张图片
        let currentSize = CGSize(width: width, height: height)
        // 开启上下文
        UIGraphicsBeginImageContext(currentSize)
        drawInRect(CGRect(origin: CGPointZero, size: currentSize))
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        // 关闭上下文
        UIGraphicsEndImageContext()
        return newImage
    }
}
